﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Imagin.Controls.Common"
    xmlns:Common.Data.Converters="clr-namespace:Imagin.Common.Data.Converters;assembly=Imagin.Common">
    <Common.Data.Converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>

    <Style TargetType="{x:Type local:Line}">
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:Line}">
                    <Grid Margin="{TemplateBinding Margin}">
                        <Border
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                        
                                <Rectangle 
                                    x:Name="PART_Rectangle" 
                                    Fill="{TemplateBinding Stroke}"/>
                        
                                <ContentPresenter 
                                    x:Name="PART_Content"
                                    Content="{TemplateBinding Content}"
                                    ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                    Margin="{TemplateBinding Padding}"
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Visibility="{Binding Content, Converter={StaticResource NullToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}"/>
                            </Grid>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Orientation" Value="Horizontal">
                            <Setter Property="Padding" Value="0,0,10,0"/>
                            
                            <Setter TargetName="PART_Rectangle" Property="Width" Value="Auto"/>
                            <Setter TargetName="PART_Rectangle" Property="Height" Value="{Binding StrokeThickness, RelativeSource={RelativeSource TemplatedParent}}"/>
                            
                            <Setter TargetName="PART_Content" Property="Grid.Row" Value="0"/>
                            <Setter TargetName="PART_Content" Property="Grid.RowSpan" Value="2"/>
                            <Setter TargetName="PART_Content" Property="Grid.Column" Value="0"/>
                            <Setter TargetName="PART_Content" Property="Grid.ColumnSpan" Value="1"/>
                            
                            <Setter TargetName="PART_Rectangle" Property="Grid.Row" Value="0"/>
                            <Setter TargetName="PART_Rectangle" Property="Grid.RowSpan" Value="2"/>
                            <Setter TargetName="PART_Rectangle" Property="Grid.Column" Value="1"/>
                            <Setter TargetName="PART_Rectangle" Property="Grid.ColumnSpan" Value="1"/>
                        </Trigger>
                        <Trigger Property="Orientation" Value="Vertical">
                            <Setter Property="Padding" Value="0,0,0,10"/>
                            
                            <Setter TargetName="PART_Rectangle" Property="Width" Value="{Binding StrokeThickness, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <Setter TargetName="PART_Rectangle" Property="Height" Value="Auto"/>
                            
                            <Setter TargetName="PART_Content" Property="Grid.Row" Value="0"/>
                            <Setter TargetName="PART_Content" Property="Grid.RowSpan" Value="1"/>
                            <Setter TargetName="PART_Content" Property="Grid.Column" Value="0"/>
                            <Setter TargetName="PART_Content" Property="Grid.ColumnSpan" Value="2"/>
                            
                            <Setter TargetName="PART_Rectangle" Property="Grid.Row" Value="1"/>
                            <Setter TargetName="PART_Rectangle" Property="Grid.RowSpan" Value="1"/>
                            <Setter TargetName="PART_Rectangle" Property="Grid.Column" Value="0"/>
                            <Setter TargetName="PART_Rectangle" Property="Grid.ColumnSpan" Value="2"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>